package br.com.aquinoevasconcelos.servlets.contato;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import br.com.aquinoevasconcelos.excecao.EmailException;
import br.com.aquinoevasconcelos.fachada.Fachada;

/**
 * Servlet implementation class ResponderContato
 */
@WebServlet("/ResponderContato")
public class ResponderContato extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public ResponderContato() {
		super();
	}

	protected void service(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {

		Fachada fachada = Fachada.getInstancia();

		String nome = request.getParameter("nome");
		String emailDestinatario = request.getParameter("email");
		String msgResposta = request.getParameter("resposta");
		String mensagem = request.getParameter("descricao");
		String titulo = request.getParameter("assunto");
		
		System.out.println(nome+emailDestinatario+ msgResposta+mensagem+titulo);

		try {
			System.out.println(nome+emailDestinatario+ msgResposta+mensagem+titulo);
			fachada.RespostaContato(nome, titulo, mensagem, msgResposta, emailDestinatario);
			
			response.sendRedirect("ListaContato");

		} catch (EmailException e) {
			response.sendRedirect("pagina_erro/erro.jsp");
			e.printStackTrace();

		}

	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		service(request, response);
	}

}
